package org.common.utils.tool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.BiConsumer;

/**
 * Future工具类
 * @author zhouzhibing
 * @date 2025/11/19 11:58
 */
public class FutureTool {

    private static final Logger log = LoggerFactory.getLogger(FutureTool.class);

    /**
     * 创建一个带有异常日志的，BiConsumer。
     * @param action BiConsumer
     * @return BiConsumer
     * @param <T> 泛型
     */
    public static <T> BiConsumer<? super T, ? super Throwable> of(BiConsumer<? super T, ? super Throwable> action) {
        return (result, throwable) -> {
            try {
                action.accept(result, throwable);
            } catch (Exception e) {
                log.error("future execute error " , e);
            }
        };
    }
}
